package com.lanou.dllo.soccernews.database;

import com.lanou.dllo.soccernews.application.BaseApplication;
import com.lanou.dllo.soccernews.bean.greendao.ArticlesEntity;
import com.lanou.dllo.soccernews.bean.greendao.DaoSession;
import com.lanou.dllo.soccernews.bean.greendao.RecommendEntity;

import java.util.List;

import de.greenrobot.dao.query.QueryBuilder;

/**
 * Created by dllo on 15/11/2.
 */
public class ArticlesDBhelp {

    private static ArticlesDBhelp articlesDBhelp;
    private static DaoSession daoSession;

    private ArticlesDBhelp() {

    }

    public static ArticlesDBhelp getInstance() {
        if (articlesDBhelp == null) {
            articlesDBhelp = new ArticlesDBhelp();
            daoSession = BaseApplication.getDaoSession();
        }

        return articlesDBhelp;
    }

    public List<ArticlesEntity> getArticlesEntity() {
        QueryBuilder<ArticlesEntity> qb = daoSession.getArticlesEntityDao().queryBuilder();
        return qb.list();
    }

    public void addArticlesEntity(List<ArticlesEntity> articles) {
        daoSession.getArticlesEntityDao().insertInTx(articles);
    }

    public  void  delete(){
        daoSession.getArticlesEntityDao().deleteAll();
    }
}
